package com.grj.parking.drools.config;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import lombok.extern.slf4j.Slf4j;
import org.apache.tomcat.util.threads.ThreadPoolExecutor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

@Slf4j
@Configuration
public class ThreadPoolConfig {

    @Bean("entryMessageExecutor")
    public ExecutorService entryMessageExecutor() {
        return new ThreadPoolExecutor(
                100,                                    // 核心线程数
                10000,                                   // 最大线程数
                60L, TimeUnit.SECONDS,                 // 空闲线程存活时间
                new LinkedBlockingQueue<>(500000),        // 任务队列
                new ThreadFactoryBuilder().setNameFormat("entry-message-%d").build(),
                new ThreadPoolExecutor.CallerRunsPolicy() // 拒绝策略
        );
    }
}